package com.qdlc.p2p.dal.model;

import org.springframework.beans.BeanUtils;

import com.qdlc.p2p.common.exception.ActivityPlanException;
import com.qdlc.p2p.common.util.Page;
import com.qdlc.p2p.common.util.StringUtil;
import com.qdlc.p2p.dal.dto.ActivityPlan;

public class ActivityPlanModel extends ActivityPlan {
	
	/** 当前页码 */
	private int page = 1;

	/** 每页数据条数 */
	private int rows = Page.ROWS;
	
	//活动方案开启 状态为1
	public static final byte ACTIVITYPLAN_STATUS_OPEN = 1;
	//活动方案关闭 状态为2 
	public static final byte ACTIVITYPLAN_STATUS_CLOSE = 2;
	
	//红包规则中文名
	private String redEnvelopeRuleName;
	//红包规则ID
	private long redEnvelopeRuleId;
	
	//体验券规则中文名
	private String experienceRuleName;
	//体验券规则ID
	private long experienceRuleId;
		
	//加息券规则中文名
	private String rateRuleName;
	//加息券规则ID
	private long rateRuleId;
	
	
	/**
	 * 修改时校验
	 */
	public void validModelData(){
		if(StringUtil.isBlank(getName())){
			throw new ActivityPlanException("方案名字不能为空",1);
		}
	}
	
	/**
	 * 把activityPlan信息copy到activityPlanModel中
	 * @param activityPlan
	 * @return
	 */
	public static ActivityPlanModel instance(ActivityPlan activityPlan) {
		ActivityPlanModel activityPlanModel = new ActivityPlanModel();
		BeanUtils.copyProperties(activityPlan, activityPlanModel);
		return activityPlanModel;
	}
	
	/**
	 * 把activityPlanModel信息copy到activityPlan中
	 * @return
	 */
	public ActivityPlan prototype() {
		ActivityPlan activityPlan = new ActivityPlan();
		BeanUtils.copyProperties(this, activityPlan);
		return activityPlan;
	}
	
	/**
	 * 修改活动方案 时须用到此方法
	 * @return
	 */
	private ActivityPlan prototypeByModify(){
		ActivityPlan activityPlan = this.prototype();
//		ActivityPlanService activityPlanService = (ActivityPlanService) BeanUtil.getBean("activityPlanService");
//		ActivityPlan activityPlan_  = activityPlanService.findById(activityPlan.getId());
//		activityPlan.setRateRule(activityPlan_.getRateRule());
		return activityPlan;
	}
	
	public String getRateRuleName() {
		return rateRuleName;
	}

	public void setRateRuleName(String rateRuleName) {
		this.rateRuleName = rateRuleName;
	}

	public String getExperienceRuleName() {
		return experienceRuleName;
	}

	public void setExperienceRuleName(String experienceRuleName) {
		this.experienceRuleName = experienceRuleName;
	}

	public String getRedEnvelopeRuleName() {
		return redEnvelopeRuleName;
	}

	public void setRedEnvelopeRuleName(String redEnvelopeRuleName) {
		this.redEnvelopeRuleName = redEnvelopeRuleName;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public long getRateRuleId() {
		return rateRuleId;
	}

	public void setRateRuleId(long rateRuleId) {
		this.rateRuleId = rateRuleId;
	}

	public long getExperienceRuleId() {
		return experienceRuleId;
	}

	public void setExperienceRuleId(long experienceRuleId) {
		this.experienceRuleId = experienceRuleId;
	}

	public long getRedEnvelopeRuleId() {
		return redEnvelopeRuleId;
	}

	public void setRedEnvelopeRuleId(long redEnvelopeRuleId) {
		this.redEnvelopeRuleId = redEnvelopeRuleId;
	}
	
}
